<template>
  <div class="flex ht100 flex-v pd-15 box-border">
    <div class="header">
      <span>{{$route.meta.title}}</span>
    </div>
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
      <el-form-item label="栏目" prop="name">
        <el-input v-model="ruleForm.name"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>


  </div>
</template>

<script>
  export default {
    data () {
      return {
        ruleForm: {
          name: '',
        },
        rules: {
          name: [
            { required: true, message: '请输入海报名称', trigger: 'blur' }
          ]
        }
      }
    },
    methods:{
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
            if(this.ruleForm.id){//update
              this.Api.updateMenu(this.ruleForm).then((response)=>{
                this.$message.success(response.data.message);
                this.$router.push({
                  name:'appMenuIndex'
                })
              })
            }else{//create
              this.Api.createMenu(this.ruleForm).then((response)=>{
                this.$message.success(response.data.message);
                this.$router.push({
                  name:'appMenuIndex'
                })
              })
            }
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      }
    },
    mounted(){
      if(this.$route.query.id){
        this.Api.getMenuDetail(this.$route.query.id).then((res)=>{
          this.ruleForm=res.data;
        })
      }
    }
  }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>

  .header{
    border-bottom: 1px solid #eee;
    margin-bottom: 10px;
    padding-bottom: 10px;
  }
  .header span{
    line-height: 40px;
    font-size: 20px;
  }

  .banner-upload-img {
    width: 600px;
    height: auto;
    display: block;
  }
  .banner-upload .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .banner-upload .el-upload:hover {
    border-color: #409EFF;
  }
  .banner-upload-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
</style>
